#ifndef __MINESWEEPER_H__
#define __MINESWEEPER_H__

#include <QMainWindow>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QTimer>
#include <QPainter>

#include "config.h"

QT_BEGIN_NAMESPACE

namespace Ui
{
    class MainGame;
}

QT_END_NAMESPACE

using namespace std;

struct Point
{
    int x;
    int y;
};

struct Data
{
    int type;
    int number;
    bool isCovered;
    bool isMarked;
    bool isError;
    bool isTouched;
};

struct Image
{
    QPixmap background;
    QPixmap block;
    QPixmap cover;
    QPixmap error;
    QPixmap mine;
    QPixmap mineError;
    QPixmap flag;
    QPixmap number[AROUND_MAX];
};

struct Timer
{
    QTimer interval;
    QTimer clock;
};

class MainGame : public QMainWindow
{
    Q_OBJECT

    private:
        Ui::MainGame* ui;
        QPoint mouse;
        Image image;
        Timer timer;

    public:
        Data tableData[TABLE_LARGE][TABLE_LARGE];
        Point mineList[MINE_INIT_COUNT];
        Point emptyList[EMPTY_COUNT];

    public:
        int status;
        int flagCount;
        int time;
        bool isWin;

    public:
        MainGame(QWidget *parent = nullptr);
        ~MainGame();

    public:
        void mainInterval();
        void clockCallback();
        void initGame();
        void loadImage();
        void setInterval();
        void connectTimer();
        void startTimer();

    public:
        void addMine();
        void addNumber();
        void gameoverWin();
        void gameoverLose(int, int);
        void update();
        void mousePressEvent(QMouseEvent*);
        void displayBlock(QPainter&);
        void displayInfo(QPainter&);
        void paintEvent(QPaintEvent*);
};
#endif
